package com.mall.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.api.OmsOrderApi;
import com.mall.dto.OmsOrderDto;
import com.mall.pageResult.PageResult;
import com.mall.pojo.OmsOrderDeliveryParam;
import com.mall.pojo.OmsOrder;
import com.mall.pojo.OmsReceiverInfoParam;
import com.mall.vo.OmsOrderVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OmsOrderService {

    @DubboReference
    private OmsOrderApi omsOrderApi;

    /**订单列表
     * 分页查询功能
     * @param omsOrderDto
     * @return
     */
    public PageResult<OmsOrder> omsOrderPage(OmsOrderDto omsOrderDto) {
        //调用api中的自定义方法进行查询;
       Page<OmsOrder> page =  omsOrderApi.omsOrderPage(omsOrderDto);
       PageResult<OmsOrder> pageRe = new PageResult<>();
       pageRe.setPageNum(omsOrderDto.getPageNum());
       pageRe.setPageSize(omsOrderDto.getPageSize());
       pageRe.setList(page.getRecords());
       pageRe.setTotalPage(Convert.toInt(page.getPages()));
       pageRe.setTotal(Convert.toInt(page.getTotal()));
       return pageRe;

    }

    /**
     * 批量删除功能
     * @param ids
     * @return
     */
    public Integer deleteOrder(List<Integer> ids) {
        //调用方法进行删除
       Integer deleteNum =  omsOrderApi.deleteOrder(ids);
       return deleteNum;

    }

    /**
     * 修改订单状态
     * @param ids
     * @param note
     * @return
     */
    public Integer updateCloseStatus(List<Integer> ids, String note) {
        //调用方法进行修改
       Integer updateNum =  omsOrderApi.updateCloseStatus(ids,note);
//返回结果
       return updateNum;
    }


    /**
     * 根据id进行查询订单列表详细信息
     * @param id
     * @return
     */
    public OmsOrderVo findOrderById(Integer id) {
        //调用方法进行查询
        OmsOrderVo omsOrderVo = omsOrderApi.findOrderById(id);

        return omsOrderVo;

    }

    /**
     * 修改备注信息
     * @param id
     * @param note
     * @param status
     * @return
     */
    public Integer updateNoteById(Long id, String note, Integer status) {

        //调用方法进行修改
Integer updateNum = omsOrderApi.updateNoteById(id,note,status);

return updateNum;


    }

    /**
     * 批量发货
     * @param deiveryParamList
     * @return
     */
    public Integer updateDeliveryByIds(List<OmsOrderDeliveryParam> deliveryParamList) {
        //调用方法
      Integer updateNum =   omsOrderApi.updateDeliveryByIds(deliveryParamList);

      return updateNum;

    }

    /**
     * 修改收货人信息
     * @param receiverInfoParam
     * @return
     */
    public Integer updateReceiverInfo(OmsReceiverInfoParam receiverInfoParam) {
        //调用方法进行修改
        Integer updateNum = omsOrderApi.updateReceiverInfo(receiverInfoParam);

        return updateNum;
    }
}
